package employee

import (
	"context"

	v1 "gitee.com/liangziyisheng/caas-platform-mc/api/employee/v1"
	"gitee.com/liangziyisheng/caas-platform-mc/internal/consts"
	"gitee.com/liangziyisheng/caas-platform-mc/internal/service"
	"gitee.com/liangziyisheng/caas-platform-mc/utility/utils"
)

func (c *ControllerV1) Update(ctx context.Context, req *v1.UpdateReq) (res *v1.UpdateRes, err error) {
	tenantCode := ctx.Value(consts.TokenClaims.TenantCode).(string)
	in := &v1.UpdateInput{}
	utils.CopyStruc(*req, in)
	in.Id = req.Id
	in.TenantCode = tenantCode

	out, err := service.Employee().Update(ctx, in)
	if err != nil {
		return nil, err
	}
	res = &v1.UpdateRes{Rows: out.Rows}
	return res, nil
}
